package kgc.crm.controller;

import kgc.crm.annotation.UserPower;
import kgc.crm.annotation.VerificationToken;
import kgc.crm.enums.PowerEnum;
import kgc.crm.model.AdminRecord;
import kgc.crm.service.IAdminRecord;
import kgc.crm.util.RequestUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
//跟进记录
@RestController
@RequestMapping("admin/record")
@CrossOrigin
public class AdminRecordController {
    @Autowired
    private IAdminRecord record;
    //添加更近记录
    @VerificationToken
    @UserPower(power = PowerEnum.SAVE)
    @PostMapping("add")
    public ResponseEntity add(@RequestBody AdminRecord adminRecord, HttpServletRequest request) {
        String apiToken = RequestUtil.getApiToken(request);
        return record.add(adminRecord,apiToken);
    }
    //修改更近记录
    @VerificationToken
    @UserPower(power = PowerEnum.UPDATE)
    @PostMapping("upd")
    public ResponseEntity upd(@RequestBody AdminRecord adminRecord ) {
        return record.upd(adminRecord);
    }
    //删除跟进记录
    @VerificationToken
    @UserPower(power = PowerEnum.DELETE)
    @PostMapping("del")
    public ResponseEntity del(@RequestBody AdminRecord adminRecord ) {
        return record.del(adminRecord.getRecordId());
    }
    //查询跟进记录
    @VerificationToken
    @UserPower(power = PowerEnum.INDEX)
    @PostMapping("sel")
    public ResponseEntity sel(@RequestBody AdminRecord adminRecord,HttpServletRequest request ) {
        return record.sel(adminRecord.getTypesId(),RequestUtil.getApiToken(request));
    }
}

